package com.gm.wj.service;

import com.gm.wj.dao.WorkPublishDAO;
import com.gm.wj.dao.WorkSubmitDAO;
import com.gm.wj.dto.WorkSubmitDTO;
import com.gm.wj.entity.WorkSubmit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class WorkSubmitService {

    @Autowired
    private WorkSubmitDAO workSubmitDAO;

    @Autowired
    private WorkPublishDAO workPublishDAO;


    /**
     * 获取列表
     * @return
     */
    public List<Map> list(){
        List<Map> list=workSubmitDAO.getList();
//        List<WorkSubmitDTO> result=new ArrayList<>();
//        WorkSubmitDTO dto=null;
//        if(list!=null&&list.size()>0){
//            for (Object o : list) {
//
//            }
//            dto.setId();
//        }
       return list;
    }


    /**
     * 保存
     * @param entity
     * @return
     */
    public boolean save(WorkSubmit entity){
        workSubmitDAO.save(entity);
        return true;
    }


    /**
     * 修改作业分数
     * @param id
     * @param score
     * @return
     */
    public boolean updateScore(Integer id,Double score){
        WorkSubmit submit = workSubmitDAO.findById(id).orElse(null);
        if(submit!=null){
            submit.setScore(score);
            submit.setStatus(1);
            workSubmitDAO.save(submit);
            return true;
        }
        return false;
    }


    /**
     * 删除
     * @param id
     * @return
     */
    public boolean delete(Integer id){
        workSubmitDAO.deleteById(id);
        return true;
    }

}
